package com.LeeCode;

/**
 * 打家劫舍
 */

public class Code198 {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 1};
        System.out.println(new Code198().rob(nums));
    }

    public int rob(int[] nums) {
        int len = nums.length;
        int[] aux = new int[nums.length];
        aux[0] = nums[0];
        if (len == 1) {
            return aux[0];
        }
        aux[1] = Math.max(nums[0], nums[1]);
        if (len == 2) {
            return aux[1];
        }
        for (int i = 2; i < len; i++) {
            aux[i] = Math.max(aux[i - 1], aux[i - 2] + nums[i]);
        }
        return aux[len - 1];
    }
}
